package com.tarena.day030;

public class OptDemo {
  public static void main(String[] args) {
    int i = 5;
    long l = 6;
    //int b =i+l;//编译错误
    long b = i+l;
    int max = 0x7fffffff;
    long c = max+1L+max+1;
    System.out.println(c); 
    //byte, short, char按照int计算
    byte d = 3;
    //byte e =  d+d;//编译错误
    //byte e = (byte)d+d;//编译错误
    byte e = (byte)(d+d);
    //Java在编译期间, 将字面量运算进行优化! 计算出结果
    char ch = 'A'+1;//char ch = 66;不超过char范围的字面量可以赋值
    //ch = 'A'+ 65535;//编译错误, 'A'+ 65535超过char的范围了!
    char cc = 'A';
    //ch = cc+1;//编译错误,
    ch = (char)(cc + 1);//变量和字面量的处理是不同的!
 //除法, 会发生下溢出
    i = 5/2;
    System.out.println(5/2); //2
    double dx = 5/2;//仍然发生下溢出
    System.out.println(dx);//2.0
    dx = 5.0/2;//5D/2
    System.out.println(dx);//2.0
    
    double price = 8888.88 * (80 / 100);
    System.out.println(price);//0.0
    
    price = 8888.88 * (80D / 100);
    System.out.println(price);//7111.103999999999
  //取余数 %
    System.out.println(5%3);//2
    
    System.out.println(-1%3);//-1
    System.out.println(0%3);//0
    System.out.println(1%3);//1
    System.out.println(2%3);//2
    System.out.println(3%3);//0
    System.out.println(4%3);//1
    System.out.println(5%3);//2
    System.out.println(6%3);//0
    System.out.println(7%3);//1
    //.....
    
    
    
    
  }

}












